package com.dmgis.qxfw.dataservice.businessservice.infoinquiry.controller;

import java.io.File;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.logging.Logger;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.dmgis.entity.DmMapPoint;

import com.dmgis.qxfw.dataservice.businessservice.api.entity.qx.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.zy.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.xt.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.yj.*;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.ResultObj;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.*;
import com.dmgis.qxfw.dataservice.businessservice.common.util.*;
import com.dmgis.qxfw.dataservice.businessservice.dmgis_mongodb_srv.dataservice.service.Impl.FileRequestService;
import com.dmgis.qxfw.dataservice.businessservice.infoinquiry.service.InformationQueryService;
import com.dmgis.qxfw.dataservice.commonservice.common.DbConfig;
import com.dmgis.qxfw.dataservice.commonservice.dmgis_mongodb_srv.dataservice.service.Impl.MongoService;
import com.dmgis.qxfw.dataservice.commonservice.utils.JsonUtil;
import com.dmgis.weblib.GridAnalysis;
import com.github.kevinsawicki.http.HttpRequest;
import org.apache.log4j.spi.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.fasterxml.jackson.core.JsonProcessingException;
import sun.net.www.content.image.gif;

@Controller
@RequestMapping("/queryInfo")
public class InformationQueryController {

    //MongoService mongoService = new MongoService();
    FileRequestService mongoService = new FileRequestService();
    @Resource
    private InformationQueryService infoQueryService;

    private final String operatingSystem;

    @Autowired
    public InformationQueryController(String operatingSystem) {
        this.operatingSystem = operatingSystem;
    }

    /**
     * 初始化城镇预报界面
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/InitCityMaxTime")
    @ResponseBody
    public Object initCityMaxTime(HttpServletRequest request, Model model) {
        forecastinfotemp infotemp = infoQueryService.getInitCityMaxTime();
        String timechar = "";
        String datechar = "";
        String timeTemp = "";
        // 加载列表
        if (infotemp != null) {
            timechar = infotemp.getTimechar().trim();
            datechar = new DateTime(infotemp.getDatechar()).toDateString().trim();// 将日期转换为字符串格式
            timeTemp = "{\"newDate\":\"" + datechar.trim() + "\",\"newTime\":\"" + timechar.trim() + "\"}";
        } else {
            timeTemp = "{}";
        }
        List<township_station> townshipstation = infoQueryService.getloadCityStation();
        String stationTemp = "[";
        // 加载列表
        if (townshipstation != null) {
            List<StationInfo> listResult = new ArrayList<StationInfo>();
            for (township_station ts : townshipstation) {
                StationInfo station = new StationInfo();
                station.setStationID(ts.getStationid());
                station.setStationName(ts.getStationname());
                listResult.add(station);
            }
            for (StationInfo sta : listResult) {
                stationTemp += "{";
                stationTemp += "\"stationID\":\"" + sta.getStationID() + "\",";
                stationTemp += "\"stationName\":\"" + sta.getStationName() + "\"";
                stationTemp += "},";
            }
            stationTemp = stationTemp.substring(0, stationTemp.length() - 1) + "]";
        } else {
            stationTemp = "[]";
        }
        ArrayList<String> result = new ArrayList<String>();
        result.add(timeTemp);
        result.add(stationTemp);
        return result;
    }


    /**
     * 当前天气显示
     *
     * @return
     */
    @RequestMapping("/weather")
    @ResponseBody
    public Object weather() {
        forecastinfotemp infotemp = infoQueryService.getInitCityMaxTime();
        List<forecastinfotemp> weather = infoQueryService.getCityForecast(infotemp, "weather");
        Forecast forecast = new Forecast();
        WebCtrlData wcd = new WebCtrlData();

        String strWeather1 = "";
        for (forecastinfotemp fit : weather) {
            strWeather1 = String.format("%02d", Integer.parseInt(WebCtrlData.WeatherNameToPicPath(fit.getWeather1().toString())));
            forecast.setStrWeather1(strWeather1.toString());
            String format = NumberFormat.getInstance().format(fit.getMaxtemp());
            forecast.setMaxTemp(format);
            forecast.setWeatherPhenomena(fit.getWeather1().toString().trim());
            String s = wcd.GetWeatherTq(strWeather1);
            forecast.setWeatherPhenomena(s);
            forecast.setWindD(wcd.GetWeatherFx(fit.getWindd1().toString()));
            forecast.setWindV(wcd.GetWeatherFs(fit.getWind1().toString()));
            forecast.setMaxhumid(fit.getMaxhumid().toString());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String format1 = sdf.format(fit.getDatechar());
            String timechar = fit.getTimechar();
            forecast.setDateTime(format1 + "日" + timechar + "时");

        }


        return forecast;
    }


    /**
     * 城镇预报查询
     *
     * @param request
     * @param model
     * @return
     * @throws ParseException
     */
    //伊宁市未来五天预报查询
    @RequestMapping("/get5DayInfo")
    @ResponseBody
    public Object get5DayInfo(HttpServletRequest request, Model model) throws ParseException {
        forecastinfotemp selectKey = new forecastinfotemp();// 查询类
        Date date1 = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date1);
        // 将时间减去24小时
        calendar.add(Calendar.HOUR_OF_DAY, 0);
        // 将分钟、秒钟和毫秒设置为0
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String strDate = sdf.format(calendar.getTime());
        DateTime dateTime = new DateTime(sdf.parse(strDate));
        calendar.setTime(date1);
        // 设置当天的16:00:00时间
        calendar.set(Calendar.HOUR_OF_DAY, 16);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        // 获取当天16:00:00的时间
        Date sixteenOClock = calendar.getTime();
        // 获取当前时间
        Date currentDate = new Date();
        // 比较当前时间与当天16:00的时间
        String strTime ="";
        if (currentDate.after(sixteenOClock)) {
         strTime = "20";// 时次
        } else {
         strTime = "08";// 时次
        }
        String stationID = "51431";// 类型
        selectKey.setDatechar(DateTime.parseDate(strDate).toDate());
        selectKey.setTimechar(strTime);
        selectKey.setStationid(stationID);
        List<forecastinfotemp> resultList = infoQueryService.get5DayInfo(selectKey, "");
        WebCtrlData wcd = new WebCtrlData();
        String temp = "[";
        if (resultList != null) {
            String xValue = "[";
            String yValue = "[";
            String yValue1 = "[";
            List<Forecast> listResult = new ArrayList<Forecast>();
            for (forecastinfotemp fit : resultList) {
                String strforcastSx = fit.getNtimes().toString().trim();
                DateTime date = dateTime.AddHours(Integer.parseInt(strforcastSx) - 12);
                SimpleDateFormat dateFm = new SimpleDateFormat("EEEE");
                String week = dateFm.format(date.toDate());

                String strDateTime = date.GetDay() + "日";
                String day = date.GetDay() + "日";


                String strWeather1 = "";
                strWeather1 = String.format("%02d", Integer.parseInt(WebCtrlData.WeatherNameToPicPath(fit.getWeather1().toString())));
                String strWeather2 = "";
                strWeather2 = String.format("%02d", Integer.parseInt(WebCtrlData.WeatherNameToPicPath(fit.getWeather2().toString())));


                String strWeatherDisp = "";
                if (strWeather1.equals("-65535")) {
                    strWeather1 = "00";
                }
                if (strWeather2.equals("-65535")) {
                    strWeather2 = "00";
                }
                if (strWeather1.equals(strWeather2))
                    strWeatherDisp = wcd.GetWeatherTq(strWeather1).toString();
                else
                    strWeatherDisp = wcd.GetWeatherTq(strWeather1).toString() + "</br>转"
                            + wcd.GetWeatherTq(strWeather2).toString();


                strWeather1 = wcd.GetWeatherTq(strWeather1).toString();
                strWeather2 = wcd.GetWeatherTq(strWeather2).toString();

                String weatherCode1 = WebCtrlData.WeatherNameToPicPath(strWeather1);
                String weatherCode2 = WebCtrlData.WeatherNameToPicPath(strWeather2);
                String strImgPic1 = "<img height='32' width='32' src='../../yili/images/tqyb/weatherDay/" + weatherCode1 + ".gif'>";
                String strImgPic2 = "<img height='32' width='32' src='../../yili/images/tqyb/weatherNight/" + weatherCode2
                        + ".gif'>";
                // String strImgPic1 = weatherCode1;
                // String strImgPic2 = weatherCode2;
                // String strImgPic1 = "<img height='32' width='32' src='${require(\"@/assets/images/tqyb/weatherDay/"+weatherCode1+".gif\")}'>";
                // String strImgPic2 = "<img height='32' width='32' src='${require(\"@/assets/images/tqyb/weatherNight/"+weatherCode2+".gif\")}'>";

                String strMinTemp = fit.getMintemp().toString().trim();
                String strMaxTemp = fit.getMaxtemp().toString().trim();
                if (strMinTemp.equals("-65535.0") || strMinTemp.equals("65535.0")) {
                    strMinTemp = "";
                }
                if (strMaxTemp.equals("-65535.0") || strMaxTemp.equals("65535.0")) {
                    strMaxTemp = "";
                }
                String strWindDir1 = "";
                String strWindDir2 = "";
                try {
                    strWindDir1 = wcd.GetWeatherFx(String.format("%d", fit.getWindd1())).toString();
                    strWindDir2 = wcd.GetWeatherFx(String.format("%d", fit.getWindd1())).toString();
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }

                if (!strWindDir1.equals(strWindDir2))
                    strWindDir1 = strWindDir1 + "</br>转" + strWindDir2;

                int minWind = Integer.parseInt(fit.getWind2().toString().substring(0, 1).trim());
                String minWindS = String.format("%02d", minWind);

                int maxWind = Integer.parseInt(fit.getWind1().toString().substring(0, 1).trim());
                String maxWindS = String.format("%02d", maxWind);
                String strWindDisp = "";
                if (minWindS.equals(maxWindS))
                    strWindDisp = wcd
                            .GetWeatherFs(String.valueOf(WebCtrlData.FengSuToFengJi(Double.parseDouble(minWindS))))
                            .toString();
                else
                    strWindDisp = wcd
                            .GetWeatherFs(String.valueOf(WebCtrlData.FengSuToFengJi(Double.parseDouble(minWindS))))
                            .toString() + " </br>转 "
                            + wcd.GetWeatherFs(String.valueOf(WebCtrlData.FengSuToFengJi(Double.parseDouble(maxWindS))))
                            .toString();
                String strRain = fit.getRain().toString().trim();
                String strHumid = fit.getMaxhumid().toString().trim();
                if (strRain.equals("-65535.0") || strRain.equals("65535.0")) {
                    strRain = "";
                }
                if (strHumid.equals("-65535.0") || strHumid.equals("65535.0")) {
                    strHumid = "";
                }
                Forecast f = new Forecast();
                f.setDateTime(strDateTime);
                f.setDay(day);
                f.setWeek(week);
                f.setWeatherPhenomena(strWeatherDisp);
                f.setStrWeather1(strWeather1);
                f.setStrWeather2(strWeather2);
                f.setMaxTemp(strMaxTemp);
                f.setMinTemp(strMinTemp);
                f.setWindD(strWindDir1);
                f.setWindV(strWindDisp);
                f.setWeatherPic1(strImgPic1);
                f.setWeatherPic2(strImgPic2);
                f.setRain(strRain);
                f.setMaxhumid(strHumid);
                listResult.add(f);

                xValue += "'" + strDateTime + "',";
                yValue += strMaxTemp + ",";
                yValue1 += strMinTemp + ",";
            }

            String tableData = "[";
            for (Forecast forecast : listResult) {
                tableData += "{";
                tableData += "\"dateTime\":\"" + forecast.getDateTime() + "\",";
                tableData += "\"maxTemp\":\"" + forecast.getMaxTemp() + "\",";
                tableData += "\"minTemp\":\"" + forecast.getMinTemp() + "\",";
                tableData += "\"windD\":\"" + forecast.getWindD() + "\",";
                tableData += "\"windV\":\"" + forecast.getWindV() + "\",";
                tableData += "\"rain\":\"" + forecast.getRain() + "\",";
                tableData += "\"humid\":\"" + forecast.getMaxhumid() + "\",";
                tableData += "\"weatherPic1\":\"" + forecast.getWeatherPic1() + "\",";
                tableData += "\"weatherPic2\":\"" + forecast.getWeatherPic2() + "\",";
                tableData += "\"weatherPhenomena\":\"" + forecast.getWeatherPhenomena() + "\",";
                tableData += "\"strWeather1\":\"" + forecast.getStrWeather1() + "\",";
                tableData += "\"strWeather2\":\"" + forecast.getStrWeather2() + "\",";
                tableData += "\"week\":\"" + forecast.getWeek() + "\",";
                tableData += "\"day\":\"" + forecast.getDay() + "\"";
                tableData += "},";
                tableData += "{";
                tableData += "\"dateTime\":\"" + forecast.getDateTime() + "\",";
                tableData += "\"maxTemp\":\"" + forecast.getMaxTemp() + "\",";
                tableData += "\"minTemp\":\"" + forecast.getMinTemp() + "\",";
                tableData += "\"windD\":\"" + forecast.getWindD() + "\",";
                tableData += "\"windV\":\"" + forecast.getWindV() + "\",";
                tableData += "\"rain\":\"" + forecast.getRain() + "\",";
                tableData += "\"humid\":\"" + forecast.getMaxhumid() + "\",";
                tableData += "\"weatherPic1\":\"" + forecast.getWeatherPic2() + "\",";
                tableData += "\"weatherPic2\":\"" + forecast.getWeatherPic2() + "\",";
                tableData += "\"weatherPhenomena\":\"" + forecast.getWeatherPhenomena() + "\",";
                tableData += "\"strWeather1\":\"" + forecast.getStrWeather1() + "\",";
                tableData += "\"strWeather2\":\"" + forecast.getStrWeather2() + "\",";
                tableData += "\"week\":\"" + forecast.getWeek() + "\",";
                tableData += "\"day\":\"" + forecast.getDay() + "\"";
                tableData += "},";
            }
            tableData = tableData.substring(0, tableData.length() - 1) + "]";
            xValue = xValue.substring(0, xValue.length() - 1) + "]";
            yValue = yValue.substring(0, yValue.length() - 1) + "]";
            yValue1 = yValue1.substring(0, yValue1.length() - 1) + "]";
            yValue = "[{name:'高温',color:'rgba(251,194,118,1)',type:'spline',tooltip:{valueSuffix: '°C'},data:" + yValue + "},"
                    + "{name:'低温',color:'rgba(150,205,247,1)',type:'spline',tooltip:{valueSuffix: '°C'},data:" + yValue1 + "}]";
            temp = tableData + "|" + xValue + "|" + yValue;
        } else {
            temp = "[]";
        }
        return temp;
    }
    @RequestMapping("/CityForecast")
    @ResponseBody
    public Object getCityForecast(HttpServletRequest request, Model model) throws ParseException {
        forecastinfotemp selectKey = new forecastinfotemp();// 查询类
        String strDate = request.getParameter("date");// 时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        DateTime dateTime = new DateTime(sdf.parse(strDate));
        String strTime = request.getParameter("sc");// 时次
        String stationID = request.getParameter("stationID");// 类型
        selectKey.setDatechar(DateTime.parseDate(strDate).toDate());
        selectKey.setTimechar(strTime);
        selectKey.setStationid(stationID);
        List<forecastinfotemp> resultList = infoQueryService.getCityForecast(selectKey, "");
        WebCtrlData wcd = new WebCtrlData();
        String temp = "[";
        if (resultList != null) {
            String xValue = "[";
            String yValue = "[";
            String yValue1 = "[";
            List<Forecast> listResult = new ArrayList<Forecast>();
            for (forecastinfotemp fit : resultList) {
                String strforcastSx = fit.getNtimes().toString().trim();
                DateTime date = dateTime.AddHours(Integer.parseInt(strforcastSx) - 12);
                SimpleDateFormat dateFm = new SimpleDateFormat("EEEE");
                String week = dateFm.format(date.toDate());

                String strDateTime = date.GetDay() + "日";
                String day = date.GetDay() + "日";


                String strWeather1 = "";
                strWeather1 = String.format("%02d", Integer.parseInt(WebCtrlData.WeatherNameToPicPath(fit.getWeather1().toString())));
                String strWeather2 = "";
                strWeather2 = String.format("%02d", Integer.parseInt(WebCtrlData.WeatherNameToPicPath(fit.getWeather2().toString())));


                String strWeatherDisp = "";
                if (strWeather1.equals("-65535")) {
                    strWeather1 = "00";
                }
                if (strWeather2.equals("-65535")) {
                    strWeather2 = "00";
                }
                if (strWeather1.equals(strWeather2))
                    strWeatherDisp = wcd.GetWeatherTq(strWeather1).toString();
                else
                    strWeatherDisp = wcd.GetWeatherTq(strWeather1).toString() + "</br>转"
                            + wcd.GetWeatherTq(strWeather2).toString();


                strWeather1 = wcd.GetWeatherTq(strWeather1).toString();
                strWeather2 = wcd.GetWeatherTq(strWeather2).toString();

                String weatherCode1 = WebCtrlData.WeatherNameToPicPath(strWeather1);
                String weatherCode2 = WebCtrlData.WeatherNameToPicPath(strWeather2);

                String strImgPic1 = "<img height='32' width='32' src='../../images/tqyb/weatherDay/" + weatherCode1 + ".gif'>";
                String strImgPic2 = "<img height='32' width='32' src='../../images/tqyb/weatherNight/" + weatherCode2
                        + ".gif'>";

                String strMinTemp = fit.getMintemp().toString().trim();
                String strMaxTemp = fit.getMaxtemp().toString().trim();
                if (strMinTemp.equals("-65535.0") || strMinTemp.equals("65535.0")) {
                    strMinTemp = "";
                }
                if (strMaxTemp.equals("-65535.0") || strMaxTemp.equals("65535.0")) {
                    strMaxTemp = "";
                }
                String strWindDir1 = "";
                String strWindDir2 = "";
                try {
                    strWindDir1 = wcd.GetWeatherFx(String.format("%d", fit.getWindd1())).toString();
                    strWindDir2 = wcd.GetWeatherFx(String.format("%d", fit.getWindd1())).toString();
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }

                if (!strWindDir1.equals(strWindDir2))
                    strWindDir1 = strWindDir1 + "</br>转" + strWindDir2;

                int minWind = Integer.parseInt(fit.getWind2().toString().substring(0, 1).trim());
                String minWindS = String.format("%02d", minWind);

                int maxWind = Integer.parseInt(fit.getWind1().toString().substring(0, 1).trim());
                String maxWindS = String.format("%02d", maxWind);
                String strWindDisp = "";
                if (minWindS.equals(maxWindS))
                    strWindDisp = wcd
                            .GetWeatherFs(String.valueOf(WebCtrlData.FengSuToFengJi(Double.parseDouble(minWindS))))
                            .toString();
                else
                    strWindDisp = wcd
                            .GetWeatherFs(String.valueOf(WebCtrlData.FengSuToFengJi(Double.parseDouble(minWindS))))
                            .toString() + " </br>转 "
                            + wcd.GetWeatherFs(String.valueOf(WebCtrlData.FengSuToFengJi(Double.parseDouble(maxWindS))))
                            .toString();
                String strRain = fit.getRain().toString().trim();
                String strHumid = fit.getMaxhumid().toString().trim();
                if (strRain.equals("-65535.0") || strRain.equals("65535.0")) {
                    strRain = "";
                }
                if (strHumid.equals("-65535.0") || strHumid.equals("65535.0")) {
                    strHumid = "";
                }
                Forecast f = new Forecast();
                f.setDateTime(strDateTime);
                f.setDay(day);
                f.setWeek(week);
                f.setWeatherPhenomena(strWeatherDisp);
                f.setStrWeather1(strWeather1);
                f.setStrWeather2(strWeather2);
                f.setMaxTemp(strMaxTemp);
                f.setMinTemp(strMinTemp);
                f.setWindD(strWindDir1);
                f.setWindV(strWindDisp);
                f.setWeatherPic1(strImgPic1);
                f.setWeatherPic2(strImgPic2);
                f.setRain(strRain);
                f.setMaxhumid(strHumid);
                listResult.add(f);

                xValue += "'" + strDateTime + "',";
                yValue += strMaxTemp + ",";
                yValue1 += strMinTemp + ",";
            }

            String tableData = "[";
            for (Forecast forecast : listResult) {
                tableData += "{";
                tableData += "\"dateTime\":\"" + forecast.getDateTime() + "\",";
                tableData += "\"maxTemp\":\"" + forecast.getMaxTemp() + "\",";
                tableData += "\"minTemp\":\"" + forecast.getMinTemp() + "\",";
                tableData += "\"windD\":\"" + forecast.getWindD() + "\",";
                tableData += "\"windV\":\"" + forecast.getWindV() + "\",";
                tableData += "\"rain\":\"" + forecast.getRain() + "\",";
                tableData += "\"humid\":\"" + forecast.getMaxhumid() + "\",";
                tableData += "\"weatherPic1\":\"" + forecast.getWeatherPic1() + "\",";
                tableData += "\"weatherPic2\":\"" + forecast.getWeatherPic2() + "\",";
                tableData += "\"weatherPhenomena\":\"" + forecast.getWeatherPhenomena() + "\",";
                tableData += "\"strWeather1\":\"" + forecast.getStrWeather1() + "\",";
                tableData += "\"strWeather2\":\"" + forecast.getStrWeather2() + "\",";
                tableData += "\"week\":\"" + forecast.getWeek() + "\",";
                tableData += "\"day\":\"" + forecast.getDay() + "\"";
                tableData += "},";
                tableData += "{";
                tableData += "\"dateTime\":\"" + forecast.getDateTime() + "\",";
                tableData += "\"maxTemp\":\"" + forecast.getMaxTemp() + "\",";
                tableData += "\"minTemp\":\"" + forecast.getMinTemp() + "\",";
                tableData += "\"windD\":\"" + forecast.getWindD() + "\",";
                tableData += "\"windV\":\"" + forecast.getWindV() + "\",";
                tableData += "\"rain\":\"" + forecast.getRain() + "\",";
                tableData += "\"humid\":\"" + forecast.getMaxhumid() + "\",";
                tableData += "\"weatherPic1\":\"" + forecast.getWeatherPic2() + "\",";
                tableData += "\"weatherPic2\":\"" + forecast.getWeatherPic2() + "\",";
                tableData += "\"weatherPhenomena\":\"" + forecast.getWeatherPhenomena() + "\",";
                tableData += "\"strWeather1\":\"" + forecast.getStrWeather1() + "\",";
                tableData += "\"strWeather2\":\"" + forecast.getStrWeather2() + "\",";
                tableData += "\"week\":\"" + forecast.getWeek() + "\",";
                tableData += "\"day\":\"" + forecast.getDay() + "\"";
                tableData += "},";
            }
            tableData = tableData.substring(0, tableData.length() - 1) + "]";
            xValue = xValue.substring(0, xValue.length() - 1) + "]";
            yValue = yValue.substring(0, yValue.length() - 1) + "]";
            yValue1 = yValue1.substring(0, yValue1.length() - 1) + "]";
            yValue = "[{name:'高温',color:'rgba(251,194,118,1)',type:'spline',tooltip:{valueSuffix: '°C'},data:" + yValue + "},"
                    + "{name:'低温',color:'rgba(150,205,247,1)',type:'spline',tooltip:{valueSuffix: '°C'},data:" + yValue1 + "}]";
            temp = tableData + "|" + xValue + "|" + yValue;
        } else {
            temp = "[]";
        }
        return temp;
    }


    /**
     * 初始化精细化预报界面
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/InitFineMaxTime")
    @ResponseBody
    public Object initFineMaxTime(HttpServletRequest request, Model model) {
        String type = request.getParameter("type");
        township_forecasttemp infotemp = infoQueryService.getInitFineMaxTime();
        String timechar = "";
        String datechar = "";
        String timeTemp = "";
        // 加载列表
        if (infotemp != null) {
            timechar = infotemp.getTimechar().trim();
            datechar = new DateTime(infotemp.getDatechar()).toDateString().trim();// 将日期转换为字符串格式
            timeTemp = "{\"newDate\":\"" + datechar.trim() + "\",\"newTime\":\"" + timechar.trim() + "\"}";
        } else {
            timeTemp = "{}";
        }
        List<township_station> townshipstation = new ArrayList<township_station>();
        if ("city".equals(type)) {
            townshipstation = infoQueryService.getloadCityStation();
        } else {
            townshipstation = infoQueryService.getloadFineStation();
        }
        String stationTemp = "[";
        // 加载列表
        if (townshipstation != null) {
            List<StationInfo> listResult = new ArrayList<StationInfo>();
            for (township_station ts : townshipstation) {
                StationInfo station = new StationInfo();
                station.setStationID(ts.getStationid().trim());
                station.setStationName(ts.getStationname().trim());
                // 乡处理
                if (station.getStationName().contains("乡")) {
                    station.setStationName(
                            station.getStationName().substring(0, station.getStationName().lastIndexOf("乡") + 1));
                }
                if (station.getStationName().contains("镇")) {
                    station.setStationName(
                            station.getStationName().substring(0, station.getStationName().lastIndexOf("镇") + 1));
                }
                if (station.getStationID().equals("S4081") || station.getStationID().equals("S4004")) {
                    continue;
                }
                listResult.add(station);
            }
            for (StationInfo sta : listResult) {
                stationTemp += "{";
                stationTemp += "\"stationID\":\"" + sta.getStationID() + "\",";
                stationTemp += "\"stationName\":\"" + sta.getStationName() + "\"";
                stationTemp += "},";
            }
            stationTemp = stationTemp.substring(0, stationTemp.length() - 1) + "]";
        } else {
            stationTemp = "[]";
        }
        ArrayList<String> result = new ArrayList<String>();
        result.add(timeTemp);
        result.add(stationTemp);
        return result;
    }

    /**
     * 精细化预报站点信息
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/loadFineStation")
    @ResponseBody
    public Object loadFineStation(HttpServletRequest request, Model model) {

        return "";
    }

    /**
     * 精细化预报查询
     *
     * @param request
     * @param model
     * @return
     * @throws ParseException
     * @throws JsonProcessingException
     */
    @RequestMapping("/FineForecast")
    @ResponseBody
    public Object getFineForecast(HttpServletRequest request, Model model)
            throws ParseException, JsonProcessingException {
        township_forecasttemp selectKey = new township_forecasttemp();// 查询类
        String strDate = request.getParameter("date");// 时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        DateTime dateTime = new DateTime(sdf.parse(strDate));
        String strTime = request.getParameter("sc");// 时次
        String stationID = request.getParameter("stationID");// 类型
        selectKey.setDatechar(DateTime.parseDate(strDate).toDate());
        selectKey.setTimechar(strTime);
        selectKey.setStationid(stationID);
        List<township_forecasttemp> resultList = infoQueryService.getFineForecast(selectKey);
        WebCtrlData wcd = new WebCtrlData();
        String temp = "[";
        if (resultList != null && resultList.size() > 0) {
            // String[] Day = new String[] { "星期日", "星期一", "星期二", "星期三", "星期四",
            // "星期五", "星期六" };
            String xValue = "[";
            String yValue = "[";
            String yValue1 = "[";
            List<FineForecast> listResult = new ArrayList<FineForecast>();
            for (int i = 0; i < resultList.size(); i += 2) {
                township_forecasttemp fcst12 = resultList.get(i);
                township_forecasttemp fcst24 = resultList.get(i + 1);
                DateTime date = dateTime.AddHours(fcst24.getNtimes() - 24 + Integer.parseInt(strTime));

                SimpleDateFormat dateFm = new SimpleDateFormat("EEEE");
                String week = dateFm.format(date.toDate());

                String strDateTime = date.GetDay() + "日";
                String day = date.GetDay() + "日";

                String strWeather1 = "";
                strWeather1 = fcst12.getWeather1().toString().trim();
                String strWeather2 = "";
                strWeather2 = fcst24.getWeather1().toString().trim();


                String strRain = fcst24.getRain().toString().trim();
                String strHumid = fcst24.getHumid().toString().replace("-65535", "-").trim();
                String weatherCode1 = WebCtrlData.WeatherNameToPicPath(strWeather1);
                String weatherCode2 = WebCtrlData.WeatherNameToPicPath(strWeather2);
//				String weatherCode1 = strWeather1;
//				String weatherCode2 = strWeather2;
                String strWeatherDisp = "";
                if (strWeather1.equals(strWeather2))
                    strWeatherDisp = strWeather1;
                else
                    strWeatherDisp = strWeather1 + "</br>转" + strWeather2;


                String strImgPic1 = "<img height='32' width='32' src='../../images/tqyb/weatherDay/" + weatherCode1
                        + ".gif'>";
                String strImgPic2 = "<img height='32' width='32' src='../../images/tqyb/weatherNight/" + weatherCode2
                        + ".gif'>";
                if (strTime == "20") {
                    strImgPic1 = "<img height='32' width='32' src='../../images/tqyb/weatherNight/" + weatherCode1 + ".gif'>";
                    strImgPic2 = "<img height='32' width='32' src='../../images/tqyb/weatherDay/" + weatherCode2 + ".gif'>";
                }
                double maxTemp = fcst24.getMaxtemp();
                double minTemp = fcst24.getMintemp();
                String windD = "";// 风向信息
                String windV = "";// 风速信息
                String windD12 = wcd.GetAllFx(fcst12.getWindd().toString().replace("-65535", "-").trim());
                String windD24 = wcd.GetAllFx(fcst24.getWindd().toString().replace("-65535", "-").trim());
                String windV12 = wcd
                        .GetWeatherFs(String.valueOf(WebCtrlData.FengSuToFengJi(fcst12.getWinds())));
                String windV24 = wcd
                        .GetWeatherFs(String.valueOf(WebCtrlData.FengSuToFengJi(fcst24.getWinds())));
                if (windD12.equals(windD24)) {
                    windD += windD12;
                } else {
                    windD += windD12 + "</br> 转" + windD24;
                }
                if (windV12.equals(windV24)) {
                    windV += windV12;
                } else {
                    windV += windV12 + "</br> 转" + windV24;
                }

                FineForecast f = new FineForecast();
                f.setDateTime(strDateTime);
                f.setMaxTemp(String.valueOf(maxTemp));
                f.setMinTemp(String.valueOf(minTemp));
                f.setHumid(Double.parseDouble(strHumid == "" ? "0" : strHumid));
                f.setRain(Double.parseDouble(strRain == "" ? "0" : strRain));
                f.setWindD(windD);
                f.setWindV(windV);
                f.setWeatherPhenomena(strWeatherDisp);
                f.setWeatherPic1(strImgPic1);
                f.setWeatherPic2(strImgPic2);
                f.setRemark(fcst12.getRemark());
                f.setStrWeather1(strWeather1);
                f.setStrWeather2(strWeather2);
                f.setDay(day);
                f.setWeek(week);
                listResult.add(f);
                FineForecast f2 = new FineForecast();
                f2.setWeatherPic1(strImgPic2);
                f2.setRemark(fcst24.getRemark());
                listResult.add(f2);
                xValue += "'" + strDateTime + "',";
                yValue += maxTemp + ",";
                yValue1 += minTemp + ",";
            }
            xValue = xValue.substring(0, xValue.length() - 1) + "]";
            yValue = yValue.substring(0, yValue.length() - 1) + "]";
            yValue1 = yValue1.substring(0, yValue1.length() - 1) + "]";
            yValue = "[{name:'高温',color:'rgba(251,194,118,1)',type:'spline',tooltip:{valueSuffix: '°C'},data:" + yValue + "},"
                    + "{name:'低温',color:'rgba(150,205,247,1)',type:'spline',tooltip:{valueSuffix: '°C'},data:" + yValue1 + "}]";
            temp = JsonUtil.object2Json(listResult) + "|" + xValue + "|" + yValue;
        } else {
            temp = "[]";
        }
        return temp;
    }


    /**
     * 初始化QPF最新时间
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/InitQPFMaxTime")
    @ResponseBody
    public Object initQPFMaxTime(HttpServletRequest request, Model model) {

        qpe_qpf infotemp = infoQueryService.getInitQPFMaxTime();
        String datechar = "";
        String timeTemp = "";
        // 加载列表
        if (infotemp != null) {
            Date datechar1 = infotemp.getDatechar();
            datechar = new DateTime(datechar1).toDateTimeString().trim();
            timeTemp = "{\"newDate\":\"" + datechar.trim() + "\"}";
        } else {
            timeTemp = "{}";
        }
        List<township_station> townshipstation = new ArrayList<township_station>();

        townshipstation = infoQueryService.getloadFineStation();

        String stationTemp = "[";
        // 加载列表
        if (townshipstation != null) {

            for (township_station ts : townshipstation) {
                stationTemp += "{";
                stationTemp += "\"pos\":\"" + ts.getLongitude() + "," + ts.getLatitude() + "\",";
                stationTemp += "\"stationName\":\"" + ts.getStationname() + "\"";
                stationTemp += "},";
            }

            stationTemp = stationTemp.substring(0, stationTemp.length() - 1) + "]";
        } else {
            stationTemp = "[]";
        }
        ArrayList<String> result = new ArrayList<String>();
        result.add(timeTemp);
        result.add(stationTemp);
        return result;
    }

    /**
     * QPF查询
     *
     * @param request
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("/QPFquery")
    @ResponseBody
    public Object getQPFForecast(HttpServletRequest request, Model model)
            throws Exception {
        String strType = request.getParameter("ntimes");// 类型
        String longitude = request.getParameter("lon");// 经度
        String latitude = request.getParameter("lat");// 纬度
        DmMapPoint dt = null;
        if (!StringUtil.IsNullOrEmpty(longitude) && !StringUtil.IsNullOrEmpty(latitude)) {
            dt = new DmMapPoint(Double.parseDouble(longitude), Double.parseDouble(latitude));
        }
        String temp = "[";
        if (strType.equals("1小时")) {
            String ntimes = "060";
            List<qpe_qpf> resultList = infoQueryService.getQPFForecast(ntimes);
            String gridpath = "";
            if (resultList != null && resultList.size() > 0) {
                String xValue = "[";
                String yValue = "[";
                SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmm");
                SimpleDateFormat format1 = new SimpleDateFormat("HH:mm");
                String urlPath;
                if (operatingSystem.equals("Windows")) {
                    urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp\\QPF\\";// 临时文件目录
                } else {
                    urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp/QPF/";
                }
                FileUtil.mkDirs(urlPath);// 创建文件夹，生成多级目录
                FileUtil.ClearTempFiles(urlPath, 1000);// 清除缓存

                for (int i = resultList.size() - 1; i >= 0; i--) {


                    String fileName = format.format(resultList.get(i).getDatechar()) + "_" + strType + ".grid";
                    String servicePath = urlPath + fileName;// 服务器文件
                    File serviceFile = new File(servicePath);// 服务器文件
                    if (serviceFile.exists()) {// 把文件上传到服务器
                        gridpath = "Temp/QPF/" + fileName;
                    } else {
                        Map<String, Object> map = new HashMap<String, Object>();
                        DateTime dateTime = new DateTime(resultList.get(i).getDatechar());
                        String time = dateTime.GetYear() + "" + dateTime.GetMonth() + "" + dateTime.GetDay() + "" + String.format("%02d", dateTime.GetHour()) + String.format("%02d", dateTime.GetMinute());
                        map.put("datechar", time);
                        map.put("type", "QPF");
                        map.put("ntimes", ntimes);
                        map.put("collectionName", "qpf_grid_file");
                        byte[] data = mongoService.selectData(map);
                        if (data == null) {
                            gridpath = "";
                        } else {
                            FileUtil.bytesToFile(data, servicePath);
                            gridpath = "Temp/QPF/" + fileName;
                        }
                    }
                    if (!"".equals(gridpath)) {
                        GridAnalysis grid = new GridAnalysis();
                        grid.openFile(servicePath);
                        double value = grid.getElevationAt(dt.x, dt.y);

                        if (value == -99999) value = 0;
                        xValue += "'" + format1.format(resultList.get(i).getDatechar()) + "',";
                        yValue += value + ",";
                    }
                }
                xValue = xValue.substring(0, xValue.length() - 1) + "]";
                yValue = yValue.substring(0, yValue.length() - 1) + "]";
                yValue = "[{name:'雨量',color:'rgba(251,194,118,1)',type:'column',tooltip:{pointFormat: '{point.y}mm'},data:[" + yValue + "}]";
                temp = xValue + "|" + yValue;
            } else {
                temp = "[]";
            }

        } else {
            try {
                DateTime time = DateTime.now();
                String[] sxlist = new String[12];
                String fileName;
                String sc = "";
                int startNtimes = time.GetHour();
                DateTime dateTime = time;
                for (int i = 0; i < sxlist.length; i++) {
                    int a = startNtimes + (i + 1);
                    if (a != 24) {
                        sxlist[i] = String.format("%03d", a % 24);
                    } else {
                        sxlist[i] = String.format("%03d", a);
                    }
                }
                if (time.GetHour() >= 0 && time.GetHour() < 8) {
                    dateTime = dateTime.AddDays(-1);
                    sc = "20";
                } else if (time.GetHour() >= 8 && time.GetHour() < 20) {
                    sc = "08";//获取当天的08时预报
                } else {
                    sc = "20";//获取当天的20时预报
                }
                if (sxlist != null && sxlist.length > 0) {
                    String gridpath = "";
                    String xValue = "[";
                    String yValue = "[";
                    String urlPath;
                    if (operatingSystem.equals("Windows")) {
                        urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp\\精细化预报\\";// 临时文件目录
                    } else {
                        urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp/精细化预报/";
                    }
                    FileUtil.mkDirs(urlPath);// 创建文件夹，生成多级目录
                    FileUtil.ClearTempFiles(urlPath, 1000);// 清除缓存
                    for (int i = 0; i < sxlist.length; i++) {
                        fileName = dateTime.toDateString() + sxlist[i] + "_" + strType + ".grid";
                        String servicePath = urlPath + fileName;// 服务器文件
                        File serviceFile = new File(servicePath);// 服务器文件
                        if (serviceFile.exists()) {// 把文件上传到服务器
                            gridpath = "Temp/精细化预报/" + fileName;
                        } else {
                            Map<String, Object> map = new HashMap<String, Object>();
                            map.put("advCode", DbConfig.advCode);
                            map.put("datechar", dateTime.toDateString());
                            map.put("type", "R");
                            map.put("ntimes", sxlist[i]);
                            map.put("forecasttype", "1");
                            map.put("timechar", sc);
                            map.put("collectionName", "ybzz_final_grid");
                            byte[] data = mongoService.selectData(map);
                            if (data == null) {
                                gridpath = "";
                            } else {
                                FileUtil.bytesToFile(data, servicePath);
                                gridpath = "Temp/精细化预报/" + fileName;
                            }
                        }
                        if (gridpath != "") {
                            GridAnalysis GridAnalysis = new GridAnalysis();
                            GridAnalysis.openFile(servicePath);
                            double value = GridAnalysis.getElevationAt(dt.x, dt.y);
                            if (value == -99999) value = 0;
                            xValue += "'" + sxlist[i].substring(1, 3) + ":00" + "',";
                            yValue += value + ",";
                        }
                    }
                    if (xValue.length() > 1) {
                        xValue = xValue.substring(0, xValue.length() - 1) + "]";
                    } else {
                        xValue = "[]";
                    }
                    if (yValue.length() > 1) {
                        yValue = yValue.substring(0, yValue.length() - 1) + "]";
                    } else {
                        yValue = "[]";
                    }
                    yValue = "[{name:'雨量',color:'rgba(251,194,118,1)',type:'column',tooltip:{pointFormat: '{point.y}mm'},data:[" + yValue + "}]";
                    temp = xValue + "|" + yValue;
                } else {
                    temp = "[]";
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return temp;
    }


    /**
     * QPF查询 精细化预报查询
     *
     * @param request
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("/QPFquery1")
    @ResponseBody
    public Object getQPFForecast1(HttpServletRequest request, Model model)
            throws Exception {
        String datetime = request.getParameter("datetime");//
        String longitude = request.getParameter("lon");// 经度
        String latitude = request.getParameter("lat");// 纬度
        DmMapPoint dt = null;
        if (!StringUtil.IsNullOrEmpty(longitude) && !StringUtil.IsNullOrEmpty(latitude)) {
            dt = new DmMapPoint(Double.parseDouble(longitude), Double.parseDouble(latitude));
        }
        String temp = "[";
        if (StringUtil.IsNullOrEmpty(datetime)) {
            String ntimes = "060";
            List<qpe_qpf> resultList = infoQueryService.getQPFForecast(ntimes);
            String gridpath = "";
            if (resultList != null && resultList.size() > 0) {
                String xValue = "[";
                String yValue = "[";
                SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmm");
                SimpleDateFormat format1 = new SimpleDateFormat("HH:mm");
                String urlPath;
                if (operatingSystem.equals("Windows")) {
                    urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp\\QPF\\";// 临时文件目录
                } else {
                    urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp/QPF/";// 临时文件目录
                }
                FileUtil.mkDirs(urlPath);// 创建文件夹，生成多级目录
                FileUtil.ClearTempFiles(urlPath, 1000);// 清除缓存
                for (int i = resultList.size() - 1; i >= 0; i--) {
                    DateTime dateTime = new DateTime();
                    String fileName = format.format(resultList.get(i).getDatechar()) + "_" + "小时" + ".grid";
                    String servicePath = urlPath + fileName;// 服务器文件
                    File serviceFile = new File(servicePath);// 服务器文件
                    if (serviceFile.exists()) {// 把文件上传到服务器
                        gridpath = "Temp/QPF/" + fileName;
                    } else {
                        Map<String, Object> map = new HashMap<String, Object>();
                        DateTime dateTime1 = new DateTime(resultList.get(i).getDatechar());
                        String time = dateTime1.GetYear() + "" + dateTime1.GetMonth() + "" + dateTime1.GetDay() + "" + String.format("%02d", dateTime1.GetHour()) + String.format("%02d", dateTime1.GetMinute());
                        map.put("type", "QPF");
                        map.put("datechar", time);
                        map.put("ntimes", ntimes);
                        map.put("collectionName", "qpf_grid_file");
                        byte[] data = mongoService.selectData(map);
                        if (data == null) {
                            gridpath = "";
                        } else {
                            FileUtil.bytesToFile(data, servicePath);
                            gridpath = "Temp/QPF/" + fileName;
                        }
                    }
                    if (!"".equals(gridpath)) {
                        GridAnalysis grid = new GridAnalysis();
                        grid.openFile(servicePath);
                        double value = grid.getElevationAt(dt.x, dt.y);

                        if (value == -99999) value = 0;
                        xValue += "'" + format1.format(resultList.get(i).getDatechar()) + "',";
                        yValue += value + ",";
                    }
                }
                xValue = xValue.substring(0, xValue.length() - 1) + "]";
                yValue = yValue.substring(0, yValue.length() - 1) + "]";
                yValue = "[{name:'雨量',color:'rgba(251,194,118,1)',type:'column',tooltip:{pointFormat: '{point.y}mm'},data:" + yValue + "}]";
                temp = xValue + "|" + yValue;
            } else {
                temp = "[]";
            }
        } else {
            try {
                DateTime time = new DateTime().parseDateTime(datetime);
                String[] sxlist = new String[24];
                String fileName;
                String sc = "";
                int startNtimes = time.GetHour();
                DateTime dateTime = time;
                for (int i = 0; i < sxlist.length; i++) {
                    int a = startNtimes + (i + 1);
                    if (a != 24) {
                        sxlist[i] = String.format("%03d", a % 24);
                    } else {
                        sxlist[i] = String.format("%03d", a);
                    }
                }
                if (time.GetHour() > 0 && time.GetHour() < 8) {
                    sc = "20";
                    dateTime = dateTime.AddDays(-1);//获取前一天的20时预报
                    startNtimes = time.GetHour() + 4 - (time.GetHour() + 4) % 3;
                } else if (time.GetHour() >= 8 && time.GetHour() < 20) {
                    sc = "08";//获取当天的08时预报
                    startNtimes = time.GetHour() - 8 - (time.GetHour() - 8) % 3;
                } else {
                    sc = "20";//获取当天的20时预报
                    startNtimes = time.GetHour() - 20 - (time.GetHour() - 20) % 3;
                }
                //获取时效
                for (int i = 0; i < sxlist.length; i++) {
                    sxlist[i] = (startNtimes + 3 * (i + 1)) + "";//获取时效,i+1,
                }
                if (sxlist != null && sxlist.length > 0) {
                    String gridpath = "";
                    String xValue = "[";
                    String yValue = "[";
                    String urlPath;
                    if (operatingSystem.equals("Windows")) {
                        urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp\\精细化预报\\";// 临时文件目录
                    } else {
                        urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp/精细化预报/";// 临时文件目录
                    }
                    FileUtil.mkDirs(urlPath);// 创建文件夹，生成多级目录
                    FileUtil.ClearTempFiles(urlPath, 1000);// 清除缓存
                    for (int i = 0; i < sxlist.length; i++) {
                        fileName = dateTime.toDateString() + sxlist[i] + "_" + time + ".grid";
                        String servicePath = urlPath + fileName;// 服务器文件
                        File serviceFile = new File(servicePath);// 服务器文件
                        if (serviceFile.exists()) {// 把文件上传到服务器
                            gridpath = "Temp/精细化预报/" + fileName;
                        } else {
                            Map<String, Object> map = new HashMap<String, Object>();
                            map.put("advCode", DbConfig.advCode);
                            map.put("datechar", dateTime.toDateString());
                            map.put("type", "R");
                            map.put("ntimes", sxlist[i]);
                            map.put("forecasttype", "1");
                            map.put("timechar", sc);
                            map.put("collectionName", "ybzz_final_grid");
                            byte[] data = mongoService.selectData(map);
                            if (data == null) {
                                gridpath = "";
                            } else {
                                FileUtil.bytesToFile(data, servicePath);
                                gridpath = "Temp/精细化预报/" + fileName;
                            }
                        }
                        if (gridpath != "") {
                            GridAnalysis GridAnalysis = new GridAnalysis();
                            GridAnalysis.openFile(servicePath);
                            double value = GridAnalysis.getElevationAt(dt.x, dt.y);
                            if (value == -99999) value = 0;
                            xValue += "'" + sxlist[i].substring(1, 3) + ":00" + "',";
                            yValue += value + ",";
                        }
                    }
                    if (xValue.length() > 1) {
                        xValue = xValue.substring(0, xValue.length() - 1) + "]";
                    } else {
                        xValue = "[]";
                    }
                    if (yValue.length() > 1) {
                        yValue = yValue.substring(0, yValue.length() - 1) + "]";
                    } else {
                        yValue = "[]";
                    }


                    yValue = "[{name:'雨量',color:'rgba(251,194,118,1)',type:'column',tooltip:{pointFormat: '{point.y}mm'},data:" + yValue + "}]";
                    temp = xValue + "|" + yValue;
                } else {
                    temp = "[]";
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return temp;

    }

    /**
     * 初始化雷达图
     *
     * @return
     */
    @RequestMapping("/initRadarPage")
    @ResponseBody
    public Object initRadarPage() {
        ArrayList<Object> arrayList = new ArrayList<Object>();
        List<doppler> dKey2 = infoQueryService.getRadarTypes();
        for (doppler dop : dKey2) {
            dop.setLdtype(DbConfig.getRaderType(dop.getLdtype()));
        }
        arrayList.add(dKey2);
        return arrayList;
    }

    /**
     * 获取雷达小时图
     *
     * @param request
     * @param model
     * @return
     * @throws JsonProcessingException
     */
    @RequestMapping("/RadHour")
    @ResponseBody
    public Object getRadHour(HttpServletRequest request, Model model) throws JsonProcessingException {
        String radid = request.getParameter("radid");
        String radtype = request.getParameter("radtype");
        String yangjiao = request.getParameter("yangjiao");
        List<doppler> dop = infoQueryService.getRadHour(radid, radtype, yangjiao);
        List<brock_lesnar> result = new ArrayList<brock_lesnar>();

        if (dop.size() > 0) {
            for (doppler dopp : dop) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("datechar", new DateTime(dopp.getDatechar()).toDateString());
                map.put("stationid", dopp.getStationid());
                double elev = dopp.getElevation();
                String elevString = (dopp.getElevation() - (int) elev) == 0 ? String.valueOf((int) elev)
                        : String.valueOf(dopp.getElevation());
                map.put("elevation", elevString);
                map.put("ldtype", dopp.getLdtype());
                map.put("timechar", dopp.getTimechar());
                map.put("collectionName", "ld_png_file");
                brock_lesnar bl = new brock_lesnar();
                bl.setTxt(dopp.getTimechar().substring(0, 2) + "时" + dopp.getTimechar().substring(2, 4) + "分");
                bl.setVal(JsonUtil.object2Json(map));
                result.add(bl);
            }
        }
        return result;
    }


    /**
     * 获取云图小时
     *
     * @param request
     * @param model
     * @return
     * @throws JsonProcessingException
     */
    @RequestMapping("/CloudHour")
    @ResponseBody
    public Object getCloudHour(HttpServletRequest request, Model model) throws JsonProcessingException {
        String cloudtype = request.getParameter("cloudtype");
        List<satellitenephoram> satellite = infoQueryService.getCloudHour(cloudtype);
        List<brock_lesnar> result = new ArrayList<brock_lesnar>();
        if (satellite.size() > 0) {
            for (satellitenephoram sat : satellite) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("datechar", new DateTime(sat.getDatechar()).toDateString());
                map.put("yttype", sat.getYttype());
                map.put("timechar", sat.getTimechar());
                map.put("collectionName", "yt_png_file");
                brock_lesnar bl = new brock_lesnar();
                bl.setTxt(sat.getTimechar().substring(0, 2) + "时" + sat.getTimechar().substring(2, 4) + "分");
                bl.setVal(JsonUtil.object2Json(map));
                result.add(bl);
            }
        }
        return result;
    }

    /**
     * 获取自动站--最大雨量
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/RainMax")
    @ResponseBody
    public Object getRainMax(HttpServletRequest request, Model model) {
        // 缺少时间段内雨量数据
        String picIndex = request.getParameter("index");
        DateTime t = DateTime.now().AddHours(-24).AddHours(Integer.parseInt(picIndex));
        String rainType = request.getParameter("rainType");
        int hour = 1;
        switch (rainType) {
            case "雨量":
                hour = 1 - 1;
                break;
            case "三小时雨量":
                hour = 3 - 1;
                break;
            case "六小时雨量":
                hour = 6 - 1;
                break;
            case "十二小时雨量":
                hour = 12 - 1;
                break;
            case "二十四雨量":
                hour = 24 - 1;
                break;
        }
        String startT = t.AddHours(-hour).toDateTimeString("yyyy-MM-dd HH:00:00");
        String endT = t.toDateTimeString("yyyy-MM-dd HH:00:00");
        List<msgmediumsmallscale> msg = infoQueryService.getRainMax(startT, endT);
        String temp = "";
        if (msg.size() == 1) {
            temp = "{\"value\":" + msg.get(0).getRain() + ",\"name\":\""
                    + msg.get(0).getStationname() + "\"}";
        }
        return temp;
    }

    /**
     * 获取自动站--最大最小温度
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/TempMaxMin")
    @ResponseBody
    public Object getTempMaxMin(HttpServletRequest request, Model model) {
        String picIndex = request.getParameter("index");
        DateTime t = DateTime.now().AddHours(-24).AddHours(Integer.parseInt(picIndex));

        String startT = t.toDateTimeString("yyyy-MM-dd HH:00:00");
        List<msgmediumsmallscale> msg = infoQueryService.getTempMax(startT);
        List<msgmediumsmallscale> msg1 = infoQueryService.getTempMin(startT);
        String temp = "";
        if (msg.size() == 1) {
            temp = "{\"maxValue\":" + msg.get(0).getMaxtemp() + ",\"maxName\":\""
                    + msg.get(0).getStationname() + "\",";

        }
        if (msg1.size() == 1) {
            temp += "\"minValue\":" + msg1.get(0).getMintemp() + ",\"minName\":\""
                    + msg1.get(0).getStationname() + "\"}";
        }
        return temp;
    }

    /**
     * 获取自动站--最大风速
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/MaxWind")
    @ResponseBody
    public Object getMaxWind(HttpServletRequest request, Model model) {
        String picIndex = request.getParameter("index");
        DateTime t = DateTime.now().AddHours(-24).AddHours(Integer.parseInt(picIndex));
        String startT = t.toDateTimeString("yyyy-MM-dd HH:00:00");
        List<msgmediumsmallscale> msg = infoQueryService.getMaxWind(startT);
        String temp = "";
        if (msg.size() == 1) {
            temp = "{\"value\":" + msg.get(0).getHexmaxwindv() + ",\"name\":\""
                    + msg.get(0).getStationname() + "\"}";
        }
        return temp;
    }

    /**
     * 获取自动站--最小湿度
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/MinHumid")
    @ResponseBody
    public Object getMinHumid(HttpServletRequest request, Model model) {
        String picIndex = request.getParameter("index");
        DateTime t = DateTime.now().AddHours(-24).AddHours(Integer.parseInt(picIndex));

        String startT = t.toDateTimeString("yyyy-MM-dd HH:00:00");
        List<msgmediumsmallscale> msg = infoQueryService.getMinHumid(startT);
        String temp = "";
        if (msg.size() == 1) {
            temp = "{\"value\":" + msg.get(0).getRelhumidity() + ",\"name\":\""
                    + msg.get(0).getStationname() + "\"}";
        }
        return temp;
    }

    /**
     * 获取自动站--最大最小气压
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/PressMaxMin")
    @ResponseBody
    public Object getPressMaxMin(HttpServletRequest request, Model model) {
        String picIndex = request.getParameter("index");
        DateTime t = DateTime.now().AddHours(-24).AddHours(Integer.parseInt(picIndex));

        String startT = t.toDateTimeString("yyyy-MM-dd HH:00:00");
        List<msgmediumsmallscale> msg = infoQueryService.getPressMax(startT);
        List<msgmediumsmallscale> msg1 = infoQueryService.getPressMin(startT);
        String temp = "";
        if (msg.size() == 1) {
            temp = "{\"maxValue\":" + msg.get(0).getMaxstationpress() + ",\"maxName\":\""
                    + msg.get(0).getStationname() + "\",";

        }
        if (msg1.size() == 1) {
            temp += "\"minValue\":" + msg1.get(0).getMinstationpress() + ",\"minName\":\""
                    + msg1.get(0).getStationname() + "\"}";
        }
        return temp;
    }

    /**
     * 获取交通预报
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/TrafficPic")
    @ResponseBody
    public Object getTrafficPic(HttpServletRequest request, Model model) {
        List<traffic> traff = infoQueryService.getTrafficPic();
        String temp = "";
        String urlPath;
        if (operatingSystem.equals("Windows")) {
            urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp\\Traffic\\";// 临时文件目录
        } else {
            urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp/Traffic/";// 临时文件目录
        }
        FileUtil.mkDirs(urlPath);//创建文件夹，生成多级目录
        FileUtil.ClearTempFiles(urlPath, 1000);//清除缓存
        if (traff.size() > 0) {
            for (traffic tra : traff) {
                String fileName = tra.getId() + ".jpg";
                String servicePath = urlPath + fileName;//服务器文件
                File serviceFile = new File(servicePath);//服务器文件
                if (serviceFile.exists()) {//把文件上传到服务器
                    temp = "Temp/Traffic/" + fileName;
                } else {
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("advCode", DbConfig.advCode);
                    map.put("id", String.valueOf(tra.getId()));
                    map.put("table_name", "base_product");
                    map.put("collectionName", "image_file");
                    byte[] data = mongoService.selectData(map);
                    if (data == null) {
                        temp = "";
                    } else {
                        FileUtil.bytesToFile(data, servicePath);
                        temp = "Temp/Traffic/" + fileName;
                    }
                }
            }
        }
        return temp;
    }

    /**
     * 获取森林预报
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/SenlinPic")
    @ResponseBody
    public Object getSenlinPic(HttpServletRequest request, Model model) {
        List<base_product> product = infoQueryService.getSenlinPic();
        String temp = "";
        String urlPath;
        if (operatingSystem.equals("Windows")) {
            urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp\\Fire\\";// 临时文件目录
        } else {
            urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp/Fire/";
        }
        FileUtil.mkDirs(urlPath);// 创建文件夹，生成多级目录
        FileUtil.ClearTempFiles(urlPath, 1000);// 清除缓存
        if (product.size() > 0) {
            for (base_product tra : product) {
                // String time = new
                // DateTime(tra.getForecasttime()).toDateTimeString();
                String id = tra.getId().toString();
                // 获取文件名称
                String fileName = id + ".jpg";
                String servicePath = urlPath + fileName;// 服务器文件
                File serviceFile = new File(servicePath);// 服务器文件
                if (serviceFile.exists()) {// 把文件上传到服务器
                    temp = "Temp/Fire/" + fileName;
                } else {
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("advCode", DbConfig.advCode);
                    map.put("id", id);
                    map.put("table_name", "base_product");
                    map.put("collectionName", "image_file");
                    byte[] data = mongoService.selectData(map);
                    if (data == null) {
                        temp = "";
                    } else {
                        FileUtil.bytesToFile(data, servicePath);
                        temp = "Temp/Fire/" + fileName;
                    }
                }
            }
        }
        return temp;
    }

    /**
     * 获取山洪灾害预报
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/FloodPic")
    @ResponseBody
    public Object getFloodPic(HttpServletRequest request, Model model) {
        List<base_product> product = infoQueryService.getFloodPic();
        String temp = "";
        String urlPath;
        if (operatingSystem.equals("Windows")) {
            urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp\\Flood\\";// 临时文件目录
        } else {
            urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp/Flood/";// 临时文件目录
        }
        FileUtil.mkDirs(urlPath);// 创建文件夹，生成多级目录
        FileUtil.ClearTempFiles(urlPath, 1000);// 清除缓存
        if (product.size() > 0) {
            for (base_product tra : product) {
                String id = tra.getId().toString();
                // 获取文件名称
                String fileName = id + ".jpg";
                String servicePath = urlPath + fileName;// 服务器文件
                File serviceFile = new File(servicePath);// 服务器文件
                if (serviceFile.exists()) {// 把文件上传到服务器
                    temp = "Temp/Flood/" + fileName;
                } else {
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("advCode", DbConfig.advCode);
                    map.put("id", id);
                    map.put("table_name", "base_product");
                    map.put("collectionName", "image_file");
                    byte[] data = mongoService.selectData(map);
                    if (data == null) {
                        temp = "";
                    } else {
                        FileUtil.bytesToFile(data, servicePath);
                        temp = "Temp/Flood/" + fileName;
                    }
                }
            }
        }
        return temp;
    }

    /**
     * 获取地灾预报
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/DZPic")
    @ResponseBody
    public Object getDZPic(HttpServletRequest request, Model model) {
        List<base_product> product = infoQueryService.getDZPic();
        String temp = "";
        String urlPath;
        if (operatingSystem.equals("Windows")) {
            urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp\\Geologic\\";// 临时文件目录
        } else {
            urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp/Geologic/";// 临时文件目录
        }
        FileUtil.mkDirs(urlPath);// 创建文件夹，生成多级目录
        FileUtil.ClearTempFiles(urlPath, 1000);// 清除缓存
        if (product.size() > 0) {
             for (base_product tra : product) {
                String id = tra.getId().toString();
                // 获取文件名称
                String fileName = id + ".jpg";
                String servicePath = urlPath + fileName;// 服务器文件
                File serviceFile = new File(servicePath);// 服务器文件
                if (serviceFile.exists()) {// 把文件上传到服务器
                    temp = "Temp/Geologic/" + fileName;
                } else {
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("advCode", DbConfig.advCode);
                    map.put("id", id);
                    map.put("table_name", "base_product");
                    map.put("collectionName", "image_file");
                    byte[] data = mongoService.selectData(map);
                    if (data == null) {
                        temp = "";
                    } else {
                        FileUtil.bytesToFile(data, servicePath);
                        temp = "Temp/Geologic/" + fileName;
                    }
                }
            }
        }
        return temp;
    }

    /**
     * 获取城市火险预报
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/CityFirePic")
    @ResponseBody
    public Object getCityFirePic(HttpServletRequest request, Model model) {
        List<base_product> product = infoQueryService.getCityFirePic();
        String temp = "";
        String urlPath;
        if (operatingSystem.equals("Windows")) {
            urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp\\CityFire\\";// 临时文件目录
        } else {
            urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp/CityFire/";// 临时文件目录
        }
        FileUtil.mkDirs(urlPath);// 创建文件夹，生成多级目录
        FileUtil.ClearTempFiles(urlPath, 1000);// 清除缓存
        if (product.size() > 0) {
            for (base_product tra : product) {
                String id = tra.getId().toString();
                // 获取文件名称
                String fileName = id + ".jpg";
                String servicePath = urlPath + fileName;// 服务器文件
                File serviceFile = new File(servicePath);// 服务器文件
                if (serviceFile.exists()) {// 把文件上传到服务器
                    temp = "Temp/CityFire/" + fileName;
                } else {
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("advCode", DbConfig.advCode);
                    map.put("id", id);
                    map.put("table_name", "base_product");
                    map.put("collectionName", "image_file");
                    byte[] data = mongoService.selectData(map);
                    if (data == null) {
                        temp = "";
                    } else {
                        FileUtil.bytesToFile(data, servicePath);
                        temp = "Temp/CityFire/" + fileName;
                    }
                }
            }
        }
        return temp;
    }

    /**
     * 获取城市内涝预报
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/CityWaterPic")
    @ResponseBody
    public Object getCityWaterPic(HttpServletRequest request, Model model) {
        List<base_product> product = infoQueryService.getCityWaterPic();
        String temp = "";
        String urlPath;
        if (operatingSystem.equals("Windows")) {
            urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp\\CityWater\\";// 临时文件目录
        } else {
            urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp/CityWater/";// 临时文件目录
        }
        FileUtil.mkDirs(urlPath);// 创建文件夹，生成多级目录
        FileUtil.ClearTempFiles(urlPath, 1000);// 清除缓存
        if (product.size() > 0) {
            for (base_product tra : product) {
                String id = tra.getId().toString();
                // 获取文件名称
                String fileName = id + ".jpg";
                String servicePath = urlPath + fileName;// 服务器文件
                File serviceFile = new File(servicePath);// 服务器文件
                if (serviceFile.exists()) {// 把文件上传到服务器
                    temp = "Temp/CityWater/" + fileName;
                } else {
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("advCode", DbConfig.advCode);
                    map.put("id", id);
                    map.put("table_name", "base_product");
                    map.put("collectionName", "image_file");
                    byte[] data = mongoService.selectData(map);
                    if (data == null) {
                        temp = "";
                    } else {
                        FileUtil.bytesToFile(data, servicePath);
                        temp = "Temp/CityWater/" + fileName;
                    }
                }
            }
        }
        return temp;
    }

    /**
     * 获取雷电潜势预报
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/ThunderFcstPic")
    @ResponseBody
    public Object getThunderFcstPic(HttpServletRequest request, Model model) {
        List<base_product> product = infoQueryService.getThunderFcstPic();
        String temp = "";
        String urlPath;
        if (operatingSystem.equals("Windows")) {
            urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp\\ThunderFcst\\";// 临时文件目录
        } else {
            urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp/ThunderFcst/";// 临时文件目录
        }
        FileUtil.mkDirs(urlPath);// 创建文件夹，生成多级目录
        FileUtil.ClearTempFiles(urlPath, 1000);// 清除缓存
        if (product.size() > 0) {
            for (base_product tra : product) {
                String id = tra.getId().toString();
                // 获取文件名称
                String fileName = id + ".jpg";
                String servicePath = urlPath + fileName;// 服务器文件
                File serviceFile = new File(servicePath);// 服务器文件
                if (serviceFile.exists()) {// 把文件上传到服务器
                    temp = "Temp/ThunderFcst/" + fileName;
                } else {
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("advCode", DbConfig.advCode);
                    map.put("id", id);
                    map.put("table_name", "base_product");
                    map.put("collectionName", "image_file");
                    byte[] data = mongoService.selectData(map);
                    if (data == null) {
                        temp = "";
                    } else {
                        FileUtil.bytesToFile(data, servicePath);
                        temp = "Temp/ThunderFcst/" + fileName;
                    }
                }
            }
        }
        return temp;
    }

    /**
     * 获取空气质量预报
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/AirPullutionPic")
    @ResponseBody
    public Object getAirPullutionPic(HttpServletRequest request, Model model) {
        List<airpol_fcst> product = infoQueryService.getAirPullutionPic();
        String temp = "";
        String urlPath;
        if (operatingSystem.equals("Windows")) {
            urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp\\AirPullution\\";// 临时文件目录
        } else {
            urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp/AirPullution/";// 临时文件目录
        }
        FileUtil.mkDirs(urlPath);// 创建文件夹，生成多级目录
        FileUtil.ClearTempFiles(urlPath, 1000);// 清除缓存
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        if (product.size() > 0) {
            for (airpol_fcst tra : product) {
                Date datechar = tra.getDatechar();
                String strDatechar = format.format(datechar);
                String ntimes = tra.getNtimes().toString();
                // 获取文件名称
                String fileName = strDatechar + ntimes + ".jpg";
                String servicePath = urlPath + fileName;// 服务器文件
                File serviceFile = new File(servicePath);// 服务器文件
                if (serviceFile.exists()) {// 把文件上传到服务器
                    temp = "Temp/AirPullution/" + fileName;
                } else {
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("advCode", DbConfig.advCode);
                    map.put("datechar", strDatechar);
                    map.put("ntimes", ntimes);
                    map.put("forecasttype", "24");
                    map.put("table_name", "airpol_fcst");
                    map.put("collectionName", "image_file");
                    byte[] data = mongoService.selectData(map);
                    if (data == null) {
                        temp = "";
                    } else {
                        FileUtil.bytesToFile(data, servicePath);
                        temp = "Temp/AirPullution/" + fileName;
                    }
                }
            }
        }
        return temp;
    }

    /**
     * 获取旅游数据
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/getDataTable")
    @ResponseBody
    public Object getDataTable(HttpServletRequest request, Model model) {
        ArrayList<Object> resultArrayList = new ArrayList<Object>();
        tour_fcst newestDate = infoQueryService.getTownshipForecastTempTime();
        List<tourResult> result = null;
        if (newestDate != null) {
            String timechar = newestDate.getTimechar().trim();
            DateTime datechar = new DateTime(newestDate.getDatechar());// 将日期转换为字符串格式
            String dateString = datechar.GetMonth() + "月" + datechar.GetDay() + "日" + timechar + "时" + datechar.GetMinute()
                    + "分";
            resultArrayList.add(dateString);// 添加日期返回结果
            // 获取旅游站点结果
            List<lvyou> resultList = infoQueryService.getDataTable(datechar.toDateString(), timechar);
            result = new ArrayList<tourResult>();
            WebCtrlData wcd = new WebCtrlData();
            String urlPath;
            if (operatingSystem.equals("Windows")) {
                urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp\\Image\\";// 临时文件目录
            } else {
                urlPath = request.getSession().getServletContext().getRealPath("/") + "Temp/Image/";// 临时文件目录
            }
            FileUtil.mkDirs(urlPath);// 创建文件夹，生成多级目录
            FileUtil.ClearTempFiles(urlPath, 100);// 清除缓存
            if (resultList != null && resultList.size() > 0) {
                for (int i = 0; i < resultList.size() - 1; i += 3) {
                    lvyou dr1 = resultList.get(i);
                    lvyou dr2 = resultList.get(i + 1);
                    // lvyou dr3 = resultList.get(i + 2);
                    String date = datechar.toDateString().trim();
                    String date1 = "";
                    String date2 = "";
                    // String date3 = "";
                    if (timechar.equals("20")) {
                        date = datechar.AddDays(1).toDateTimeString("yyyy-MM-dd");
                        date2 = datechar.AddDays(2).toDateTimeString("yyyy-MM-dd");
                    } else {
                        date2 = datechar.AddDays(1).toDateTimeString("yyyy-MM-dd");
                    }
                    date1 = date;
                    String wd1 = dr1.getMintemp().toString() + "℃ ～ " + dr1.getMaxtemp().toString() + "℃";
                    String wd2 = dr2.getMintemp().toString() + "℃ ～ " + dr2.getMaxtemp().toString() + "℃";
                    String weather11 = wcd.GetWeatherTq(WebCtrlData.WeatherNameToPicPath(dr1.getWeather1()));
                    String weather12 = wcd.GetWeatherTq(WebCtrlData.WeatherNameToPicPath(dr1.getWeather2()));
                    String weather21 = wcd.GetWeatherTq(WebCtrlData.WeatherNameToPicPath(dr2.getWeather1()));
                    String weather22 = wcd.GetWeatherTq(WebCtrlData.WeatherNameToPicPath(dr2.getWeather2()));
                    String stationname = dr1.getStationname();
                    String stationId = dr1.getStationid().trim();
                    String text = dr1.getText();
                    String fileName = stationId + ".jpg";
                    String webUrl = "";// 文件网络相对路径
                    String servicePath = urlPath + fileName;// 服务器文件
                    File serviceFile = new File(servicePath);// 服务器文件
                    if (serviceFile.exists()) {// 把文件上传到服务器
                        webUrl = "Temp/Image/" + fileName;
                    } else {
                        Map<String, Object> map = new HashMap<String, Object>();
                        map.put("advCode", DbConfig.advCode);
                        map.put("stationid", stationId);
                        map.put("collectionName", "image_file");
                        byte[] data = mongoService.selectData(map);
                        if (data == null) {
                            webUrl = "";
                        } else {
                            FileUtil.bytesToFile(data, servicePath);
                            webUrl = "Temp/Image/" + fileName;
                        }
                    }
                    String WeatherPhenomena;
                    String WeatherPhenomena2;
                    if (!weather11.equals(weather12)) {
                        WeatherPhenomena = weather11 + "转" + weather12;
                    } else {
                        WeatherPhenomena = weather11;
                    }
                    if (!weather21.equals(weather22)) {
                        WeatherPhenomena2 = weather21 + "转" + weather22;
                    } else {
                        WeatherPhenomena2 = weather21;
                    }
                    tourResult touur = new tourResult();
                    touur.setDate1(date1);
                    touur.setDate2(date2);
                    touur.setWd1(wd1);
                    touur.setWd2(wd2);
                    touur.setWeather11(weather11);
                    touur.setWeather12(weather12);
                    touur.setWeather21(weather21);
                    touur.setWeather22(weather22);
                    touur.setWeatherphenomena(WeatherPhenomena);
                    touur.setWeatherphenomena2(WeatherPhenomena2);
                    touur.setStationname(stationname);
                    touur.setImagePath(webUrl);
                    touur.setFxfs1(dr1.getWinds());
                    touur.setFxfs2(dr2.getWinds());
                    touur.setText(text);
                    result.add(touur);
                }
            }
        }
        resultArrayList.add(result);
        return resultArrayList;
    }


    /**
     * 获取指数
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/getZhishu")
    @ResponseBody
    public Object getZhishu(HttpServletRequest request, Model model) {
        List<zhishu> list = infoQueryService.getZhishu();
        // 加载列表
        Map<String, String> zs = new HashMap<String, String>();
        zs.put("ZZ", "着装气象指数");
        zs.put("ZW", "紫外线指数");
        zs.put("YS", "雨伞指数");
        zs.put("LYOU", "旅游气象指数");
        zs.put("JT", "交通气象指数");
        zs.put("CL", "晨练气象指数");
        zs.put("WR", "空气污染气象");
        zs.put("GM", "感冒指数");

        String strText = "";
        if (list != null && list.size() != 0) {
            DateTime date = new DateTime(list.get(0).getDatechar());
            String sc = list.get(0).getTimechar();
            String dtime = date.GetYear() + "年" + date.GetMonth() + "月" + date.GetDay() + "日" + sc + "指数预报";
            StringBuilder cont = new StringBuilder();
            cont.append("<ul  class='quantity'>");
            for (zhishu row : list) {
                for (String key : zs.keySet()) {
                    String zhishu = zs.get(key);
                    String level = "";
                    String note = "";
                    if (key.equals("ZZ")) {
                        cont.append("<li style='border-right: solid 1px #E8E8E8;border-bottom:  solid 1px #E8E8E8;'>");
                        level = row.getZzgrade().toString();
                        note = row.getZztext().toString();
                    }
                    if (key.equals("ZW")) {
                        cont.append("<li style='border-bottom: solid 1px #E8E8E8;'>");
                        level = row.getZwgrade().toString();
                        note = row.getZwtext().toString();
                    }
                    if (key.equals("YS")) {
                        cont.append("<li style='border-right: solid 1px #E8E8E8;border-bottom: solid 1px #E8E8E8;'>");
                        level = row.getYsgrade().toString();
                        note = row.getYstext().toString();
                    }
                    if (key.equals("LYOU")) {
                        cont.append("<li style='border-right: solid 1px #E8E8E8;border-bottom: solid 1px #E8E8E8;'>");
                        level = row.getLyougrade().toString();
                        note = row.getLyoutext().toString();
                    }
                    if (key.equals("JT")) {
                        cont.append("<li style='border-right: solid 1px #E8E8E8;border-bottom: solid 1px #E8E8E8;'>");
                        level = row.getJtgrade().toString();
                        note = row.getJttext().toString();
                    }
                    if (key.equals("CL")) {
                        cont.append("<li style='border-bottom:solid 1px #E8E8E8;'>");
                        level = row.getClgrade().toString();
                        note = row.getCltext().toString();
                    }
                    if (key.equals("WR")) {
                        cont.append("<li style='border-right:solid 1px #E8E8E8;border-bottom: solid 1px #E8E8E8;'>");
                        level = row.getWrgrade().toString();
                        note = row.getWrtext().toString();
                    }
                    if (key.equals("GM")) {
                        cont.append("<li style='border-right: solid 1px #E8E8E8;border-bottom: solid 1px #E8E8E8;'>");
                        level = row.getGmgrade().toString();
                        note = row.getGmtext().toString();
                    }
                    cont.append("<img src='image/zhishu/" + zhishu + ".png' style='width:30px;height:30px' >");
                    cont.append("<p>" + zhishu + "</p>");
                    cont.append("<p>" + level + "</p>");
                    cont.append("</li>");
                }

            }
            strText += cont.toString() + "</ul>";
        }
        return list;
    }


    /**
     * 获取预警信号
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/getSignalInfo")
    @ResponseBody
    public Object getSignalInfo(HttpServletRequest request, Model model) {
        // warn_signal_info 缺少 announcedtime 时间的预警数据
        List<warn_signal_info> list = infoQueryService.getSignalInfo();
        // 加载列表
        return list;
    }

    /**
     * 获取重要天气
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/ImportWtTipInfo")
    @ResponseBody
    public Object getImpWtInfoTip(HttpServletRequest request, Model model) {
        List<important_weather> list = infoQueryService.GetImpWtInfoTip();
        String temp = "[";
        // 加载列表
        List<ImportantWeather> listResult = new ArrayList<ImportantWeather>();
        if (list != null && list.size() > 0) {
            for (important_weather imw : list) {
                ImportantWeather iw = new ImportantWeather();
                iw.setStationId(imw.getStationid().toString());
                iw.setStationName(imw.getStationname().toString());
                iw.setObservTime(new DateTime(imw.getObservetime()).toDateString());
                iw.setType(imw.getWeathertype().toString());
                iw.setDetail(imw.getWeatherdetail().toString());
                listResult.add(iw);
            }
            for (ImportantWeather sta : listResult) {
                temp += "{";
                temp += "\"stationId\":\"" + sta.getStationId() + "\",";
                temp += "\"stationname\":\"" + sta.getStationName() + "\",";
                temp += "\"observtime\":\"" + sta.getObservTime() + "\",";
                temp += "\"type\":\"" + sta.getType() + "\",";
                temp += "\"detail\":\"" + sta.getDetail() + "\"";
                temp += "},";
            }
            temp = temp.substring(0, temp.length() - 1) + "]";
        } else {
            temp = "[]";
        }
        return listResult;
    }

    /**
     * 获取预警提示版
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/WarningInfoTip")
    @ResponseBody
    public Object getWarnInfoTip(HttpServletRequest request, Model model) {
        List<warn_signal_info> list = infoQueryService.GetWarnInfoTip();
        String temp = "[";
        // 加载列表
        if (list != null && list.size() > 0) {
            if (list.size() > 0) {
                for (warn_signal_info wsi : list) {
                    temp += "{";
                    temp += "\"Type\":\"" + wsi.getType() + "\",";
                    temp += "\"Color\":\"" + wsi.getColor() + "\",";
                    temp += "\"County\":\"" + wsi.getCounty() + "\"";
                    temp += "},";
                }
            }
            temp = temp.substring(0, temp.length() - 1);
            temp += "]";
        } else {
            temp = "[]";
        }
        return temp;
    }


    /**
     * @param
     * @return 首页右上角常德天气实况
     * @author
     * @date 2019/12/19
     **/
    @RequestMapping("/CityForecastByLX")
    @ResponseBody
    public Object getCityForecastByLX(HttpServletRequest request) throws ParseException {
        // msgmediumsmallscale 缺 observtime 数据
        Date scaleNewDate = infoQueryService.getScaleNewDate();
        DateTime nowtime = DateTime.now();
        String s = nowtime.toDateTimeString("yyyy-MM-dd HH") + ":00:00";
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
        String format1 = format.format(scaleNewDate);
        List<MediumSmallScale> msg = infoQueryService.GetHomepagemsg(format1);
        return msg;
    }

    /***
     * 初始化水位站
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/WeaterStation")
    @ResponseBody
    public Object WeaterStation(HttpServletRequest request, Model model) {
        List<water_obsrv_sta_info> list = infoQueryService.WeaterStation();
        return list;
    }

    /**
     * 水位监测曲线图
     *
     * @param
     * @return
     * @author ymf
     * @date 2019/12/23
     **/
    @RequestMapping("/WaterChart")
    @ResponseBody
    public Object WaterChart(HttpServletRequest request) {
        String startDate = request.getParameter("startDate") + ":00:00";
        String endDate = request.getParameter("endDate") + ":59:59";
        String stationname = request.getParameter("stationname");
        List<reservoir_water_info> list = infoQueryService.WaterChart(startDate, endDate, stationname);
        String temp = "";
        if (list != null && list.size() > 0) {
            String xValue = "[";
            String yValue = "[";
            String yyValue = "[";
            for (reservoir_water_info r : list) {
                xValue += "'" + new DateTime(r.getObservtime()).toDateTimeString("MM-dd HH:mm") + "',";
                yValue += r.getWaterlevel() + ",";
                yyValue += r.getLimited_waterlv() + ",";
            }
            xValue = xValue.substring(0, xValue.length() - 1) + "]";
            yValue = yValue.substring(0, yValue.length() - 1) + "]";
            yyValue = yyValue.substring(0, yyValue.length() - 1) + "]";
            yValue = "[{name:'水位',data:" + yValue + "}]";
            yyValue = "[{name:'汛限水位',data:" + yyValue + "}]";
            temp = xValue + "|" + yValue + "|" + yyValue;
        }
        return temp;
    }

    /**
     * 获取最近的10条灾害点数据
     *
     * @param zhdPagingModel 查询参数，包含经纬度信息
     * @return
     */
    @RequestMapping("/selectZhdByDist")
    @ResponseBody
    public Object selectZhdByDist(ZhdPagingModel zhdPagingModel, HttpSession session) {
        try {
            List<potential_points> data = null;
            if (zhdPagingModel.getLon() != 0 && zhdPagingModel.getLat() != 0) {
                data = infoQueryService.selectZhdByDist(zhdPagingModel);
            }
            return new ResultObj("查询成功！", data, true);
        } catch (Exception ex) {
            ex.printStackTrace();
            return new ResultObj(ex.getMessage(), null, false);
        }
    }

    @RequestMapping("/Tourforecast")
    @ResponseBody
    public Object Tourforecast(HttpServletRequest request) {
        String startDate = request.getParameter("startDate");
        String type = request.getParameter("type");
        Object touristProduct = infoQueryService.getTouristProduct(-1, "景观预报", startDate, request);
        return touristProduct;
    }
}